// Package Stream 流式api
package Stream

// CanToStream T是切片 map 怎么定义
type CanToStream interface {
	map[any]any
	[]any
}
type Stream[T CanToStream] struct {
	Data     T
	funcList []func(stream *Stream[T]) any
}

func (receiver *Stream[T]) Get() any {
	var res any = nil
	for i := range receiver.funcList {
		res = receiver.funcList[i](receiver)
	}
	return res
}

func (receiver *Stream[T]) MapThis(f func(*Stream[T]) any) *Stream[T] {
	_ = append(receiver.funcList, f)
	return receiver
}

func toStream[T CanToStream](data T) *Stream[T] {
	st := new(Stream[T])
	st.Data = data
	return st
}
